package com.thread;

//静态方法的同步锁
//当一个静态方法上使用synchronized修饰后，那么该方法一定具有同步效果
public class SyncDemo4 {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> Foo.doSome());
        Thread t2 = new Thread(() -> Foo.doSome());

        t1.start();
        t2.start();
    }

}

class Foo {
    //Foo.class是指类对象

    //public synchronized static void doSome() {
    public static void doSome() {
        synchronized (Foo.class) {
            Thread thread = Thread.currentThread();
            System.out.println(thread.getName() + "开始执行");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(thread.getName() + "执行完毕");
        }
    }
}
